import sys

import dropsecure

if __name__ == "__main__":
    from optparse import OptionParser
    parser = OptionParser()
    parser.add_option("-p", "--put", action="store_true", dest = "put",
                      default=False, help="Put the file")
    parser.add_option("-g", "--get", action="store_true", dest = "get",
                      default=False, help="get the file")
    parser.add_option("-f","--file", dest="filename", default=None,
                     help="filename to put or get")
    parser.add_option("-l", "--list", action="store_true", dest="list",
                      help="view stored file names")
    parser.add_option("-k", "--key", dest="aesKey", default=None,
                      help="Key to ne used with AES to encrypt RSA keys")
    (options, args) = parser.parse_args()
    if options.aesKey == None:
        print "aesKey is required"
        sys.exit(1)

    if not options.get and not options.put and not options.list:
        print "Either put, get or list option is required"
        sys.exit(1)

    ds = dropsecure.DS(options.aesKey)

    if options.list:
        ds.list_files()
        sys.exit(0)

    filename = options.filename
    if filename == None:
        print "filename is required"
        sys.exit(1)

    if options.get:
        ds.get_file(filename)
    elif options.put:
        ds.put_file(filename)

 #   manager = KeyManager(options.aesKey)
 #   key = manager.getKey();
 #   proc = FileProc(key)

 #   if options.get:
 #       if options.filename == None:
 #           proc.list()
 #       else:
 #           proc.get(options.filename)

 #   if options.put:
 #       if options.filename == None:
 #           print "filename required to put"
 #           sys.exit(1)
 #       else:
 #           proc.put(options.filename)

 #   if options.list:
 #       proc.list()
